package com.zt.ztzx.service.impl;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zt.ztzx.model.entity.product.ProductBatches;
import com.zt.ztzx.model.vo.common.Result;
import com.zt.ztzx.service.ProductBatchesService;
import com.zt.ztzx.mapper.ProductBatchesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 16236
* @description 针对表【product_batches】的数据库操作Service实现
* @createDate 2024-09-20 10:02:02
*/
@Service
public class ProductBatchesServiceImpl extends ServiceImpl<ProductBatchesMapper, ProductBatches>
    implements ProductBatchesService{

    @Autowired
    private ProductBatchesMapper productBatchesMapper;

    @Override
    public Result<PageInfo<ProductBatches>> findAll(Integer pageNum, Integer pageSize, String productName) {
        PageHelper.startPage(pageNum, pageSize);
        List<ProductBatches> products = productBatchesMapper.findAll(productName);
        PageInfo<ProductBatches> pageInfo = new PageInfo<>(products);
        return Result.build(pageInfo,200,"查询成功");
    }

    @Override
    public Result add(ProductBatches productBatches) {
        if(productBatches == null){
            return Result.build(null,400,"参数错误");
        }
        productBatches.setRecoverydate(new DateTime());
        productBatchesMapper.insert(productBatches);
        return Result.build(null,200,"添加成功");
    }

    @Override
    public Result updateData(ProductBatches productBatches) {
        if(productBatches == null){
            return Result.build(null,400,"参数错误");
        }
        productBatchesMapper.updateById(productBatches);
        return Result.build(null,200,"修改成功");
    }

    @Override
    public Result removeData(Long id) {
        productBatchesMapper.deleteById(id);
        return Result.build(null,200,"删除成功");
    }
}




